//
//  PreTransactionSellerCell.swift
//  Share
//
//  Created by admin on 2020/12/7.
//  Copyright © 2020 MBA. All rights reserved.
//

import SwiftUI

struct PreTransactionSellerCell: View {
    
    var store: Store
    var share: Share
    @State var percent: Float = 0
    
    var body: some View {
        let storeout = store.price * (Float( share.ratioOut) ?? 1.05)
        let profit = (storeout - store.price)*Float(store.num)

            HStack(alignment: .center){
                
              
                VStack{
                    Progress( percent: self.percent*100)
                        .frame(width: 44, height: 44, alignment: /*@START_MENU_TOKEN@*/.center/*@END_MENU_TOKEN@*/)
                    Text("卖价：\(storeout ,specifier: "%0.3f")")
                        .font(.system(size: 10))
                     
                }
              
                
               VStack(alignment: .leading){
                       
                        Text("数量：\(store.num)")
                        Text("收益:\(profit , specifier: "%0.2f")")
                        Text("成本:\(store.price , specifier: "%0.3f")")
                    }
                    .padding(.horizontal)
                    .font(.system(size: 10))
                    .foregroundColor(.grey_2)
            }
            .padding(.all)
            .background(Color("background3"))
            .cornerRadius(4)
            .shadow(color: Color.shadow_1.opacity(0.5), radius: 2, x: 0, y: 0)
            .onAppear{
            
                self.percent = (Float(share.price) ?? 0.0001)/storeout
            }
  
        }
  
        
    
    

    
}

struct PreTransactionSellerCell_Previews: PreviewProvider {
    static var previews: some View {
        PreTransactionSellerCell(store: Store._stores[0], share:Share._shares[0])
    }
}
